package opera;

import book.*;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 邓大帅
 * Date: 2022-12-20
 * Time: 10:00
 */
public class AddOperation implements IOperation {
    public void work(BookList bookList) {
        System.out.println("增加图书");
        Scanner input = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = input.nextLine();
        System.out.println("请输入作者");
        String author = input.nextLine();
        System.out.println("请输入价格");
        int price = input.nextInt();
        System.out.println("请输入类型");
        String type = input.nextLine();
        Book book = new Book(name,author,price,type);
            int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
            Book temp = bookList.getBook(i);
            if (temp.getName().equals(name)) {
                System.out.println("这本书已存在，无需重复添加");
                return;
            }
        }
        bookList.setBook(book);
        bookList.setUseSize(currentSize+1);
        System.out.println("完成操作");
    }
}
